package com.shortvedio.content.api;

import com.baomidou.mybatisplus.extension.api.R;
import com.shortvedio.base.context.BaseContext;
import com.shortvedio.base.utils.JwtUtil;
import com.shortvedio.content.dto.VideosContentDto;
import com.shortvedio.content.service.VedioContentService;
import com.shortvedio.base.model.Result;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.RequestOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/videos")
public class VedioContentController {

    @Autowired
    private VedioContentService vedioContentService;

    @PostMapping("like_vedio") //点赞
    public Result likeVedio(@RequestParam Long vedioId){
        Long userId = BaseContext.getCurrentId();
        Result result = vedioContentService.addLike(userId, vedioId);
        return result;
    }

    @DeleteMapping("delete_like")  //删除点赞
    public Result deleteLike(@RequestParam Long vedioId){
        Long userId = BaseContext.getCurrentId();
        Result result = vedioContentService.deleteLie(userId, vedioId);
        return result;
    }

    @PostMapping("user_to_concern")  //关注
    public Result userToConcern(@RequestParam Long targetUserId){
        Long userId = BaseContext.getCurrentId();
        Result result = vedioContentService.AddConcern(userId, targetUserId);
        return result;
    }

    @DeleteMapping("delete_concern")  //取消关注
    public Result deleteConcern(@RequestParam Long targetUserId){
        Long userId = BaseContext.getCurrentId();
        Result result = vedioContentService.deleteConcern(userId, targetUserId);
        return result;
    }

    @PostMapping("add_user_favorites")  //收藏
    public Result addFavorites(@RequestParam Long favoritesId,@RequestParam Long videoId){
        Long userId = BaseContext.getCurrentId();
        Result result = vedioContentService.addFavorites(favoritesId, userId, videoId);
        return result;
    }

    @DeleteMapping("delete_user_favorites")  //删除收藏
    public Result deleteFavorites(@RequestParam Long favoritesId,@RequestParam Long videoId){
        Long userId = BaseContext.getCurrentId();
        Result result = vedioContentService.deleteFavorites(favoritesId, userId, videoId);
        return result;
    }

    @PostMapping("add_video_content")  //添加短视频
    public Result addVideoContent(@RequestBody VideosContentDto videosContentDto){
        Long userId = BaseContext.getCurrentId();
        videosContentDto.setUserId(userId);
        Result result = vedioContentService.addVideoContent(videosContentDto);
        return result;
    }

    @PostMapping("issue_video")  //发布短视频
    public Result issueVideo(@RequestParam Long videoId){
        Long userId = BaseContext.getCurrentId();
        Result result = vedioContentService.issueVideo(videoId, userId);
        return result;
    }

    @DeleteMapping("delete_video") //删除短视频
    public Result deleteVideo(@RequestParam Long videoId){
        Long userId = BaseContext.getCurrentId();
        Result result = null;
        try {
            result = vedioContentService.deleteVideo(userId, videoId);
        } catch (IOException e) {
            return Result.error("删除失败");
        }
        return result;
    }


    @PostMapping("add_look")  //添加浏览量
    public void addLook(@RequestParam Long videoId){
        vedioContentService.addLook(videoId);
    }



}
